package com.github;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName EchoController
 * @Description TODO
 * @Author shuang669539827@163.com
 * @Date2019/3/11 9:35
 * @Version v1.0
 **/
@RestController
public class EchoController {

    @Autowired
    private  RestTemplate restTemplate;

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
    public String echo(@PathVariable String str) {
        System.out.println("str:"+str);
        return restTemplate.getForObject("http://service-provider/echo/" + str, String.class);
    }

}
